use warnings;
use strict;
no warnings qw(redefine);

my %abr = (
	'XviD' => 'SR', 'X264' => 'SR', 'SD' => 'SR', 'SR' => 'SR', 'BoxSD' => 'SR', 
	'720p' => 'HR', '1080p' => 'HR', 'HD' => 'HR', 'HR' => 'HR', 'x264' => 'HR', 'BoxHD' => 'HR', 
	'Anime' => 'HS', 'Documentary' => 'HS', 'Sport' => 'HS', 'Foreign' => 'HS', 'Other' => 'HS', 'Others' => 'HS', 
	'DVD' => 'DD', 
# 	'WMV-HD' => 'WV', 
# 	'NDS' => 'NDS', 'PS3' => 'PS3', 'PSP' => 'PSP', 'Wii' => 'Wii', 'WiiWare-VC' => 'WW', 'XBOX 360 DLC' => 'X3D', 'Xbox' => 'XB', 'Xbox 360' => 'X3', 
# 	'3D' => '3D', 'BluRay' => 'BR', 'Foreign' => 'Fo', 'HD' => 'HD', 'SD' => 'SD', 'other' => 'Ot', 
# 	'Audiobook' => 'AB', 'Lossless' => 'Ll', 'MP3' => 'MP3', 'Video' => 'Vi', 
# 	'0day' => '0d', 'Games' => 'Ga', 'ISO' => 'ISO', 'Mac' => 'MAC', 
# 	'PC-Phone' => 'Ph', 'Mobile-Android' => 'And', 'Mobile-Other' => 'Ot', 'Mobile-iOS' => 'iOS', 
# 	'Anime' => 'An', 'Documentary' => 'Do', 'Foreign' => 'Fo', 'HD' => 'HD', 'Other' => 'Ot', 'SD' => 'SD', 'Sport' => 'Sp', 
# 	'DVD' => 'DVD', 'ImgSet' => 'IS', 'Pack' => 'Pa', 'WMV' => 'WMV', 'x264' => '264', 
# 	'Comics' => 'Co', 'Ebook' => 'eB', 'Misc' => 'Mi',
);

sub ParsePage {
	#my ($page, $cat_name, $type) = @_; # name and type are only used for item &GetLinks call
	my ($page, $cat_name, $user_agent, $site, $type, $max_nzbs) = @_;
	#my $file = 'tv all nzbsorg'; # movies sd nzbsorg tv xvid nzbsorg tv sd nzbsu movies blueray nzbsu
	#my $s_type = 'ep'; # yr or ep
	#my $sh = {};
	my $an = 0; # TODO start at 100 to allow 1-100 watchlist matches
	my $free = 99; # unused/changed but needed
	my $new_nzbs = 0;
	my $sh = {}; # site hash of hashes
	my $spaces = '&nbsp;&nbsp;&nbsp;';
	my $lang = '';
	my $tt = '';
	my $size = '';
	my $message = '';
	#my $nnn; # to be used for db have check
	my %mon = (Jan => 1,Feb => 2,Mar => 2,Apr => 4,May => 5,Jun => 6,Jul => 7,Aug => 8,Sep => 9,Oct => 10,Nov => 11,Dec => 12);

	my $description;
	my $start = 0;
	my $wrap = 0;
	
	#my $pages = 0;

	my $cat_num = 0;
	my $dst_cat; # newznab cat > ppweb cat/destination cat
	#my $found = 0;
	#my $of = '';
	#my $have = '';
	
	foreach (@{$page}) {
		# utf8 > &#nnn;
		#s/([^\x20-\x7F])/'&#'.ord($1).';'/gse;
		# no listings failure
		if (m!^(?:[ \t]+)?<newznab:response offset="0" total="0" />! or (m!^</rss>! and !$start)){# or m!^<category></category>!){
			$sh->{1} = {
				orig_title	=> 'Failed',
				details		=> 'No nzb listings found',
			};
		}
		elsif (m!^(?:[ \t]+)?<newznab:response offset="(\d+)" total="(\d+)" />!){
			my $offset = $1; # 0 50 100 150 200 250
			my $total = $2;
			
			# pagination
			if ($total > 50){
				$sh->{99}{'orig_title'} = 'pagination';
				$sh->{99}{'got'} = $total;
				$sh->{99}{'details'} = $offset;
				$sh->{99}{'a_name'} = 99;
				$sh->{99}{'grabs'} = 0;
			}
		}
		# newznab error
		elsif (m!^(?:[ \t]+)?<error code="(\d+)" description="([^"]+)" ?/>!){
			$sh->{1} = {
				orig_title	=> 'Failed',
				details		=> 'Site returned error: '.$2.' ('.$2.')',
			};
		}
		elsif (m!^(?:[ \t]+)?<item>!){ $start = 1; }
		elsif (!$start){ next; }

		#elsif (m!^\t{1,3}<title>([^<]+)</title>!){ + dogzip
		elsif (m!^[ \t]+<title>([^<]+)</title>!){
			$an ++;
			$sh->{$an}{'orig_title'} = $1;
			$sh->{$an}{'orig_title'} =~ s!%([a-fA-F0-9]{2,2})!chr(hex($1))!eg;
			$sh->{$an}{'got'} = '';
			$sh->{$an}{'details'} = ''; # allows empty addition later
			$sh->{$an}{'a_name'} = $an;

			# MOVED to <category> so we can pass $type
# 			($sh->{$an}{'title'}, $sh->{$an}{'label'}, $sh->{$an}{'sub_label'}, $sh->{$an}{'tail'}, $lang, $sh->{$an}{'s'}, $sh->{$an}{'e'}) = &StripTitle ($sh->{$an}{'orig_title'}, $cat_name, $type);
# 			if ($lang){ 
# 				$lang = $spaces.'lang: <B class="WARNING">'.$lang.'</B>'; 
# 				# grey skip label entries
# 				#if ($lang =~ m!($VAR{'SkipLang'})!i){ $sh->{$an}{'got'} = 'skip lang match'; }
# 			}
		}
		# nzb id - for building fetch URLS
		elsif (m!^[ \t]+<guid isPermaLink="(?:true|false)">(?:.+/)?([^/]+)</guid>!){ # (?:.+/)? for nzbsu URL, nzbsorg is just id
			$sh->{$an}{'nzb_id'} = $1;
		}
		# nzb link - for fetching during update
		elsif (m!^[ \t]+<link>([^<]+)</link>!){
			$sh->{$an}{'url'} = $1;
			$sh->{$an}{'url'} =~ s!&amp;!&!g; # gets re-encoded by LWP otherwise
			
			# dognzb site details link
			if ($site eq 'Dognzb' and $sh->{$an}{'url'} =~ m!http://dognzb.cr/fetch/(.+)/$VAR{'DN_Key'}!){
				$sh->{$an}{'nzb_id'} = $1;
				$sh->{$an}{'links'} = "<a href=\"http://dognzb.cr/details/$1\">Dognzb</a>";
			}
				
		}
		# site details link	nzbs.in uses #nzb-info-comments
		elsif (m!^[ \t]+<comments>([^<]+)#(?:nzb-info-)?comments</comments>!){
			$sh->{$an}{'links'} = "<a href=\"$1\">$site</a>";
		}
		# category is before description and all newznab attributes $site_cat =~ s![ :>-]+!/!;Serien
		elsif (m!^[ \t]+<category>([^ ]+).*?[;:>-] ?(?:Si?erie[sn]-|Do[ck]u-)?(.+)</category>!){
			my $nn_pcat = $1;
			my $nn_scat = $2;
			my $nn_cat = $1.'/'.$2;
			unless ($cat_name =~ m!$nn_scat$!){ # $cat_name = cat-sub-cat?
# 				if ($abr{$nn_scat}){
# 					$sh->{$an}{'details'} = $spaces.'cat: '.$nn_scat.' ('.$abr{$nn_scat}.')';
# 				}
# 				else { $sh->{$an}{'details'} = $spaces.'cat: '.$nn_scat; }
				$sh->{$an}{'details'} = $spaces.'cat: '.$nn_scat;
			}
			# for watch res check, only used for TV - SR and HR only IIRC
			if ($nn_pcat eq 'TV'){ 
				$sh->{$an}{'res'} = $abr{$nn_scat};
				#$sh->{$an}{'res'} = $XX_res{$nn_scat}; # not passed
			}
			
			# check custom routing - full, parent or child match
			if ($VAR{'NN_Cats'} and ($VAR{'NN_Cats'} =~ m!\b$nn_cat:([^|]+)!i or $VAR{'NN_Cats'} =~ m!\b$nn_pcat:([^|]+)!i or $VAR{'NN_Cats'} =~ m!\b$nn_scat:([^|]+)!i)){
				$dst_cat = $1;
			}
			# check for Tv/Vid type and set routing if not done above
			if ($nn_pcat eq 'TV'){ 
				unless ($dst_cat){ $dst_cat = $VAR{'TvNzbs'}; }
				$type = 'Tv';
			}
			elsif ($nn_pcat eq 'Movies'){ 
				unless ($dst_cat){ $dst_cat = $VAR{'VidNzbs'}; }
				$type = 'Vid';
			}
			
			# MOVED strip title down to where we have type ###
			($sh->{$an}{'title'}, $sh->{$an}{'label'}, $sh->{$an}{'sub_label'}, $sh->{$an}{'tail'}, $lang, $sh->{$an}{'s'}, $sh->{$an}{'e'}, $sh->{$an}{'m'}) = &StripTitle ($sh->{$an}{'orig_title'}, $cat_name, $type);
			if ($lang){ 
				$lang = $spaces.'lang: <B class="WARNING">'.$lang.'</B>'; 
			}
			
			#&Print ('cats '.$nn_cat.' '.$nn_pcat.' '.$nn_scat.' '.$VAR{'NN_Cats'}.' '.$dst_cat.' (UP01)', 4, 0);

			# watchlist res match - since have title match don't need 'res' check, there will be one
			# need to translate (abr hash) so SR/HR will match listing SD/HD
			#if ($found and $abr{$wh->{$title}{'res'}} eq $res){
			#	$found .= 'res';				
			#}
		}

		# ### DESCRIPTION ###
		# dognzb only
		elsif ($site eq 'Dognzb' and m!^\t{3,5}<description><\!\[CDATA\[(.+)<br /> ]]></description>!i){ #http://dognzb.cr/details
			$description = $1;
			$description =~ s!</?b>!!ig;
			my @post = split (m!<br />!, $description);
			foreach (@post){ # Name, Category, Size, Added
				# already set by earlier <category> match
				#if (m!Category: .+[;:>-] (.+)!){
				#	unless ($cat_name eq $cat){
				#		$sh->{$an}{'details'} = $spaces.'cat: '.$cat;
				#	}
					#$sh->{$an}{'res'} = $abr{$cat}; # already set by earlier cat match
				#}
				if (m!Size: (.+)!){
					$sh->{$an}{'details'} = $spaces.'Details: '.$1.$sh->{$an}{'details'}.$lang;
# 					if ($cat_name and $cat_name =~ m!(TV|Movies|Shows)!){ $sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang; }
# 					elsif ($dst_cat){ $sh->{$an}{'details'} = $spaces.$1.$sh->{$an}{'details'}.$lang; }
# 					else { $sh->{$an}{'details'} = 'Details:'.$spaces.$1.$sh->{$an}{'details'}.$lang; }
				}
				elsif (m!Added: \w{3}, (\d{2}) (\w{3}) (\d{4})!){
					# dupe age calc
					my $o_year = $3;
					my $o_mon = $2;
					my $o_day = $1;
					
					unless ($DateTime[2] eq $o_mon.' '.$o_day.' '.$o_year){
						#my %mon = (Jan => 1,Feb => 2,Mar => 2,Apr => 4,May => 5,Jun => 6,Jul => 7,Aug => 8,Sep => 9,Oct => 10,Nov => 11,Dec => 12);
						$o_mon = $mon{$o_mon} - 1;
						#my ($day,$lmon,$year) = (localtime)[3,4,5];
						#$year += 1900;
						#my $days = (($year * 365) + (($lmon + 1) * 30) + $day) - (($o_year * 365) + ($o_mon * 30) + $o_day);
						my $days = $DateTime[3] - (($o_year * 365) + ($o_mon * 30) + $o_day);
						$sh->{$an}{'age'} = $days;
# 						if ($days >= 10){
# 							$sh->{$an}{'details'} .= $spaces.'age: <B class="WARNING">'.$days.'</B>';
# 						}
# 						else { $sh->{$an}{'details'} .= $spaces.'age: '.$days; }
						$sh->{$an}{'details'} .= $spaces.'age: '.$days;
					}
				}
			}
		}
		# single line CDATA - nzbsorg, nzbsu which doesn't have last div, nzbhq which doesn't have nested <ul>s
		# works, but was only using for formated Size and it/CDATA is not available in search results.
# 		elsif (m!^\t<description><\!\[CDATA\[.*?<ul><li>(.+?)</li></ul>(?:</li></ul>)?</div><div style="clear:both;">(?:</div>)?]]>!){
# 			$description = $1;
# 		}
# 		# wrapping CDATA open
# 		elsif (m!^\t<description><\!\[CDATA\[.*?<ul><li>([^\]]+)!){
# 			$description .= $1;
# 			$wrap = 1;
# 		}
# 		# wrapping CDATA close
# 		elsif ($wrap and m!^([^\t]+)</li></ul>(?:</li></ul>)?</div><div style="clear:both;">(?:</div>)?]]>!){
# 			$description .= $1;
# 		}
# 		# wrapping CDATA - > 2 lines - no open or close
# 		elsif ($wrap and m!^([^\t\]]+)!){
# 			$description .= $1;
# 		}
# 		#
# 		elsif (m!^\t</description>! and $description){
# 			$wrap = 0;# 
# 			if ($description =~ m!(.+)</li><li>(?:Show Info:|Imdb Info:)<ul><li>(.+)!){
# 				my @post = split (m!</li><li>!, $1);
# 				#my @info = split (m!</li><li>!, $2);
# 				# ID, Name, Size, Attributes: Category - <a, Groups, Poster, PostDate, Password, Nfo (nzbsu only)
# 				foreach (@post){ 
# 					#if (m!([^:]+): (.+)!){
# 					if (m!Size: (.+) ?!){
# 						#$sh->{$an}{'Size'} = $1;
# 						$size = $spaces.$1;
# 						last;
# 						#$post->{$sh->{$an}{'title'}}{$1} = $2;
# 						# $post->{$sh->{$an}{'title'}}{'Size'}
# 					}
# 				}
# 				# TV
# 				# nzbs org
# 				# Title, Show, Aired, <a href="http://www.tvrage
# 				
# 				# movies
# 				# nzbs org 6.2 (5376 votes)
# 				# Title (title/year), Rating (num/votes), Plot, Year, Genre (|), Director (|), Actors (|), 
# 				# nzbsu Rating: <span style="font-weight:bold; color:#FFAA2A;">5.3</span>
# 				# IMDB Link (title), Rating (num), Plot, Year, Genre (, ), Director (, ), Actors (, ), 
# # 				foreach (@info){ 
# # 					#if (m!([^:]+): (.+)!){
# # 					#if (m!Rating: (.+)! and $1 =~ m!^\d!){
# # 					# Nzbsu (><) and Nzbsorg (spaces)
# # 					if (m!Rating:.*[ >]([\d.]+)[ <]!){
# # 						$sh->{$an}{'Rating'} = $1;
# # 						#$info->{$sh->{$an}{'title'}}{$1} = $2;
# # 						# $info->{$sh->{$an}{'title'}}{'Aired'}
# # 					}
# # 					if (m!Year: (\d{4})!){
# # 						$sh->{$an}{'Year'} = $1;
# # 						#$info->{$sh->{$an}{'title'}}{$1} = $2;
# # 						# $info->{$sh->{$an}{'title'}}{'Aired'}
# # 					}
# # 					# IMDB Nzbsu, Nzbsin
# # 					if (m!IMDB Link: .*/(tt\d+)/!){
# # 						$sh->{$an}{'tt'} = $1;
# # 					} # Nzbsorg
# # 					elsif(m!Title: .*/(tt\d+)/!){
# # 						$sh->{$an}{'tt'} = $1;
# # 					}
# # 				}
# 			}
# 			# Nzbsu TV - no @info and added @post Nfo
# 			else {# ($description =~ m!\[CDATA\[.*<ul><li>(.+)</li></ul></div>!){
# 				my @post = split (m!</li><li>!, $description);
# 				foreach (@post){ 
# 					if (m!Size: (.+) ?!){
# 						#$sh->{$an}{'Size'} = $1;
# 						$size = $spaces.$1;
# 						last;
# 						#print "$1 = $2\n";
# 						#$post->{$sh->{$an}{'title'}}{$1} = $2;
# 						# $post->{$sh->{$an}{'title'}}{'Size'}
# 					}
# 				}
# 				
# 			}
# 		}
# 		# END DESCRITION

		# ### newznab:attr's ###
		# two category lines parent followed by child
# 		elsif (m!^\t<newznab:attr name="category" value="(\d+)" />!){
# 			if ($cat_num){
# 				my $cat = $1;
# 				if ($Sites{$site}{$cat}){
# 					&Print ('  Got '.$site.' cat match: '.$Sites{$site}{$cat}.' (NNC2)', 4, 0);
# 				}
# 				else { &Print ('  Did not find cat match for: '.$cat.' (NNC3)', 4, 0); }
# 			}
# 			# ignore first match, mark seen
# 			else { $cat_num = 1; }
# 		}
# 		# size VS CDATA formated Size (^uc)
		elsif (m!^[ \t]+<newznab:attr name="size" value="(\d+)" />!){
			my $bytes = $1;
			my $mb = sprintf("%.0f", $bytes / 1048576);
			$sh->{$an}{'size'} = $mb;
			#if ($bytes > 1073741824){
			if ($bytes > 990000000){
				$size = sprintf("%.2f", $bytes / 1073741824).' GB';
			}
			else { $size = sprintf("%.2f", $bytes / 1048576).' MB'; }
			if ($VAR{'MaxSize'} and $mb > $VAR{'MaxSize'}){
				$size = $spaces.'<B class="WARNING">'.$size.'</B>';
			}
			else { $size = $spaces.$size; }
			
			# dognzb - api search only 
# 			if ($site eq 'Dognzb' and $sh->{$an}{'details'} !~ m!^Details!){
# 				if ($cat_name and $cat_name =~ m!(TV|Movies|Shows)!){ $sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang; }
# 				elsif ($dst_cat){ $sh->{$an}{'details'} = $spaces.$size.$sh->{$an}{'details'}.$lang; }
# 				else { $sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang; }
# 				#$sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang;
# 				#if ($dst_cat){ $sh->{$an}{'details'} =~ s!Details:!!; }
# 			}
			# dognzb - api search only 
			if ($site eq 'Dognzb'){
				$sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang;
			}
		}
		# files
		# poster
		
		# ### TV ###
		# season
#  		elsif (m!^\t<newznab:attr name="season" value="S(0?(\d+))" />!){
# 			$sh->{$an}{'EpLabel'} = 's'.$1; # s0n part of sNNeNN (ep appended next)
# 			$sh->{$an}{'ep_num'} = $2; # (n)n part of (n)nnn (ep appended next, no leading 0)
# 			$sh->{$an}{'season'} = 's'.$1; # for db season match (nothing appended, has leading 0)
# 		}
		# episode
# 		elsif (m!^\t<newznab:attr name="episode" value="E(\d+)" />!){
# 			$sh->{$an}{'EpLabel'} .= 'e'.$1; # sNNeNN
# 			$sh->{$an}{'ep_num'} .= $1; # (n)nnn
# 			$sh->{$an}{'episode'} = $1; # nn/0n
# 		}
		# season date based
# 		elsif (m!^\t<newznab:attr name="season" value="(20(\d{2}))" />!){
# 			$sh->{$an}{'ep_date'} = $2; # \d{2} part of \d{2}-\d{2}-\d{2} (-\d{2}-\d{2} appended next)
# 			$sh->{$an}{'season'} = $1; # for db season match - s.$sh->{$an}{'season'} works
# 		}
		# episode date based
# 		elsif (m!^\t<newznab:attr name="episode" value="(\d{2})/(\d{2})" />!){
# 			$sh->{$an}{'ep_date'} .= '-'.$1.'-'.$2;
# 		}
		# rage id # http://derefer.me/?http://www.tvrage.com/shows/id-18689
		elsif (m!^\t<newznab:attr name="rageid" value="(\d+)" />!){
			#$sh->{$an}{'rage_id'} = $1;
			my $id = $1;
			if ($site eq 'Kerews'){
				$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://kere.ws/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
			}
			elsif ($site eq 'Nzbsu'){
				$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://www.nzb.su/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
				#$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://tardwagon.com/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
			}
			elsif ($site eq 'Nzbsin'){
				$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://nzbs.in/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
			}
			elsif ($site eq 'Pwnzb'){
				$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://pwnzb.com/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
			}
			elsif ($site eq 'Nzbtv'){
				$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://nzbtv.net/series/$1\">eps</A>$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$1\">TVRage</A>";
			}
			else {
				$sh->{$an}{'links'} .= "$spaces<A HREF=\"http://derefer.me/?http://www.tvrage.com/shows/id-$id\">TVRage</A>";
			}
			
		}
		# tvdb id NZBSU
# 		elsif (m!^\t<newznab:attr name="tvdb-show" value="(\d+)" />!){
# 			$sh->{$an}{'tvdb_id'} = $1;
# 		}
		# series id  http://nzbs.org/series/1728 need site urls for eps link
		elsif (m!^\t<newznab:attr name="seriesid" value="(\d+)" />!){
			my $id = $1;
			if ($site eq 'Nzbsorg'){
				$sh->{$an}{'links'} =~ s!(.+?)$spaces!$1&nbsp;<A HREF=\"http://nzbs.org/series/$id\">eps</A>$spaces!;
			}
		}
		# showtitle
# 		elsif (m!^\t<newznab:attr name="showtitle" value="([^"]+)" />!){
# 			$sh->{$an}{'showtitle'} = $1;
# 			#$sh->{$an}{'showtitle'} =~ s! &(amp;)? ! And !g;
# 			#$sh->{$an}{'showtitle'} =~ s!&#?\w+;!!g;
# 			#if ($sh->{$an}{'showtitle'} ne $sh->{$an}{'title'}){
# 			#	$sh->{$an}{'showtitle'} .= ' '.$sh->{$an}{'title'};
# 			#}
# 		}
		# tvtitle can be Season 3, Episode 2
# 		elsif (m!^\t<newznab:attr name="tvtitle" value="([^"]+)" />!){
# 			$sh->{$an}{'ep_title'} = $1;
# 			$sh->{$an}{'ep_title'} =~ s! &(amp;)? ! And !g;
# 			$sh->{$an}{'ep_title'} =~ s!&#?\w+;!!g;
# 		}
		# tvairdate                  name="tvairdate" value="Tue, 17 Apr 2012
# 		elsif (m!^\t<newznab:attr name="tvairdate" value="\w{3}, (\d{2}) (\w{3}) \d{2}(\d{2}))!){ # d m y
		elsif (m!^\t<newznab:attr name="tvairdate" value="(\w{3}, \d{2} \w{3} \d{4})!){ # d m y
# 			#$sh->{$an}{'tvairdate'} = $2.'-'.$1.'-'.$3; # m d y
# 			my $o_mon = $mon{$2}
# 			$sh->{$an}{'details'} = $spaces.'Aired: '.$o_mon.'-'.$1.'-'.$3; # m d y
			$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$1.'">aired</A>';
		}
# 		elsif (m!^\t<newznab:attr name="tvairdate" value="\w{3}, \d{2} \w{3} \d{2}(\d{2})"!){ # d m y
# 			if ($1 < 12){
# 				$sh->{$an}{'tv_yr'} = '\''.$1; # '\d\d
# 				# do aired: year for any old shows? - Aired: '68, Yr: '68... do all Yr: '12
# 			}
# 		}


		# grabs
		elsif (m!^[ \t]+<newznab:attr name="grabs" value="(\d+)" />!){
			# details has cat. size and lang, if they exist, have leading spaces
			$sh->{$an}{'grabs'} = $1;
			if ($1){
				# size category grabs
				$sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$spaces.'grabs: '.$1.$lang;
			}
			# size category
			else { $sh->{$an}{'details'} = 'Details:'.$size.$sh->{$an}{'details'}.$lang; }
			
# 			# ### not sure why age isn't showing up 12/13
# 			if ($sh->{$an}{'age'} and $sh->{$an}{'details'} !~ m!$sh->{$an}{'age'}!){
# 				$sh->{$an}{'details'} .= $spaces.'age: '.$sh->{$an}{'age'};
# 			}
			#if ($dst_cat and $dst_cat !~ m!(TV|Movies)!){ $sh->{$an}{'details'} =~ s!Details:!!; }
			#if ($cat_name and $cat_name !~ m!(TV|Movies)!){ $sh->{$an}{'details'} =~ s!Details:!!; }
			
			#$size = '';
		}
		# comments
		elsif (m!^[ \t]+<newznab:attr name="comments" value="(\d+)" />!){
			# already have have site details link, add comments
			if ($1){
				my $c = $1;
				$sh->{$an}{'links'} =~ s!$site</a>!$site ($c)</a>!;
			}
		}
# 		# password
# 		elsif (m!^\t<newznab:attr name="password" value="([^"]+)" />!){
# 			if ($1){ $sh->{$an}{'details'} .= $spaces.'<B class="WARNING">pwd</B>'; }
# 			#if ($1){ $sh->{$an}{'password'} = $1; }
# 		}
		# completion
		elsif (m!^\t<newznab:attr name="completion" value="(\d+)" />!){
			if ($1 and $1 < 100){ 
				my $percent = $1;
				$sh->{$an}{'complete'} = $percent;
				#$sh->{$an}{'details'} .= $spaces.'<B class="WARNING">incomplete ('.$1.'%)</B>'; 
				$sh->{$an}{'details'} =~ s!$size!$size <B class="WARNING">($percent%)</B>!;
			}
			$size = '';
		}
		# usenetdate    <newznab:attr name="usenetdate" value="Sat, 23 May 2009 09:55:25 +0000" />
		elsif (m!^[ \t]+<newznab:attr name="usenetdate" value="\w{3}, (\d{2}) (\w{3}) (\d{4})!){ # d m y 23 Apr 2012
			my $o_year = $3;
			my $o_mon = $2;
			my $o_day = $1;
			if ($DateTime[2] =~ m!$o_mon (\d+) $o_year!){
				my $days = ($1 - $o_day);
				if ($days > 0){
					$sh->{$an}{'age'} = $days;
					$sh->{$an}{'details'} .= $spaces.'age: '.$days;
				}
			}
			else {		
			#unless ($DateTime[2] eq $o_mon.' '.$o_day.' '.$o_year){
				$o_mon = $mon{$o_mon} - 1;

				# gloabal or passed?
				#my ($day,$lmon,$year) = (localtime)[3,4,5];
				#$year += 1900;
				#my %mon = (Jan => 1,Feb => 2,Mar => 2,Apr => 4,May => 5,Jun => 6,Jul => 7,Aug => 8,Sep => 9,Oct => 10,Nov => 11,Dec => 12);
				#$o_mon = $mon{$o_mon},
				#my $days = (($year * 365) + (($lmon + 1) * 30) + $day) - (($o_year * 365) + ($o_mon * 30) + $o_day);
				#my $c_days = $DateTime[3] = my $c_days = ($year * 365) + $yday;
				my $days = $DateTime[3] - (($o_year * 365) + ($o_mon * 30.437) + $o_day);
				$days =~ s!^(\d+)\.\d+!$1!;
				if ($an == 50){
					&Print ('   '.$days.' = '.$DateTime[3].' - (('.$o_year.' * 365) + ('.$o_mon.' * 30.437) + '.$o_day.')', 5, 0);
				}
				$sh->{$an}{'age'} = $days;
				#if ($VAR{'MaxAge'} and $days >= $VAR{'MaxAge'}){
				if ($days > 0){
					$sh->{$an}{'details'} .= $spaces.'age: '.$days;
					#$sh->{$an}{'details'} .= $spaces.'age: <B class="WARNING">'.$days.'</B>';
				}
			}
		}
		# poster
		elsif (m!^\t<newznab:attr name="poster" value="([^"]+)" />!){
			$sh->{$an}{'poster'} = $1;
		}
		# group
		elsif (m!^\t<newznab:attr name="group" value="([^"]+)" />!){
			$sh->{$an}{'group'} = $1;#grabs: '.$1
			#$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$1.'">group</A>';
			#$sh->{$an}{'details'} =~ s!($spaces)grabs:!$spaces<A TITLE="posted by $sh->{$an}{'poster'} to $sh->{$an}{'group'}">group</A>$1grabs:!;
			$sh->{$an}{'details'} .= $spaces.'<A TITLE="posted by '.$sh->{$an}{'poster'}.' to '.$sh->{$an}{'group'}.'">group</A>';
		}


		# ### Movies - These may be out of order ###
# 		# coverurl - value="http://nzbs.org/covers/movies/1935179-cover.jpg" />
# 		elsif (m!^\t<newznab:attr name="coverurl" value="([^"]+)" />!){
# 			$sh->{$an}{'coverurl'} = $1;
# 		}
		# genre
		elsif (m!^\t<newznab:attr name="genre" value="([^"]+)" />!){
			#$sh->{$an}{'genre'} = $1;
			#$sh->{$an}{'genre'} =~ s!\|!, !g;
			my $genre = $1;
			$genre =~ s!\|!, !g;
			#$sh->{$an}{'details'} = $spaces.$genre;
			$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$genre.'">genre</A>';
		}
		# imdb
		elsif (m!^[ \t]+<newznab:attr name="imdb" value="(\d+)" />!){
			# already have site link (cmts)
			$tt = $1;
			if (($type and $type eq 'Vid') or $cat_name eq 'My-Cart'){ # don't want when Tv includes an imdb attribute
# 				if ($site eq 'Kerews'){
# 					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://kere.ws/movies?foreign=1&imdb=$tt\">rls</A>";
# 				}
				if ($site eq 'Nzbsorg'){
					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://nzbs.org/movies/$tt\">rls</A>";
				}
				elsif ($site eq 'Nzbsu'){
					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://www.nzb.su/movies?imdb=$tt\">rls</A>";
				}
# 				elsif ($site eq 'Nzbsu'){ 
# 					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://tardwagon.com/showmovie?imdb=$tt\">rls</A>";
# 				}
				elsif ($site eq 'Nzbsin'){
					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://nzbs.in/movies?imdb=$tt\">rls</A>";
				}
				elsif ($site eq 'Pwnzb'){
					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://pwnzb.com/movies?imdb=$tt\">rls</A>";
				}
				elsif ($site eq 'Nzbtv'){
					$sh->{$an}{'links'} .= "&nbsp;<A HREF=\"http://nzbtv.net/movies?imdb=$tt\">rls</A>";
				}
			}
			$sh->{$an}{'links'} .= "$spaces<A HREF=\"http://derefer.me/?http://www.imdb.com/title/tt$tt/\">IMDb</A>";
		}
# 		# rating RSS
# 		elsif (m!^[ \t]+<newznab:attr name="rating" value="([\d.]+)" />!){
# 			# want nzbsorg rating (num) from CDATA VS this (no num)
# # 			unless ($sh->{$an}{'Rating'}){
# # 				$sh->{$an}{'Rating'} = $1;
# # 			}
# 			# already have imdb link, add rating
# 			my $rate = $1;
# 			$sh->{$an}{'links'} =~ s!IMDb</A>!IMDb ($rate)</A>!
# 		}
		# rating API AND RSS
		elsif (m!^[ \t]+<newznab:attr name="(?:imdbscore|rating)" value="([\d.]+)" />!){
			# already have imdb link, add rating
			my $rate = $1;
			$sh->{$an}{'links'} =~ s!IMDb</A>!IMDb ($rate)</A>!
		}
		# predb - Nzbsorg
		elsif (m!^[ \t]+<newznab:attr name="pred"!){
			$sh->{$an}{'details'} .= $spaces.'scene';
		}
		# nuke - Nzbsorg
		elsif (m!^[ \t]+<newznab:attr name="nuke" value="([^"]+)" />!){
			$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$1.'"><B class="WARNING">nuke</B></A>';
		}
		elsif (m!^[ \t]+<newznab:attr name="imdbplot" value="([^"]+)" />!){
			my $plot = $1;
			# utf8 > &#nnn;
			$plot =~ s/([^\x20-\x7F])/'&#'.ord($1).';'/gse;

			$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$plot.'">plot</A>';
		}
		elsif (m!^[ \t]+<newznab:attr name="imdbactors" value="([^"]+)" />!){
			my $actors = $1;
			# utf8 > &#nnn;
			#$plot =~ s/([^\x20-\x7F])/'&#'.ord($1).';'/gse;
			$actors =~ s!\|!, !g;
			$sh->{$an}{'details'} .= $spaces.'<A TITLE="'.$actors.'">actors</A>';
		}

		# ### end of listing, get/add queue links ###
		elsif (m!^(?:[ \t]+)?</item>!){ # my ($site, $cat_name, $an, $sh, $tt) = @_;
# 			if ($found){
# 				&Print ("  $sh->{$an}{'title'} has $found (WF01)", 3, 0);
# 				$found = 0;
# 			}
			#$sh = &Get_Links ($site, $cat_name, $an, $sh->{$an}, $tt, $nn_cat);
			($sh, $free, $new_nzbs, $max_nzbs, $message) = &Get_Links ($site, $cat_name, $an, $sh, $tt, $user_agent, $free, $new_nzbs, $type, $max_nzbs, $dst_cat, $message);
			if ($sh->{$an}{'title'} =~ m!^-+$!){ delete $sh->{$an}; }
			$tt = '';
			$dst_cat = '';
		}
	}
	unless ($sh){
		$sh->{1} = {
			orig_title	=> 'Failed',
			details		=> 'Unrecognized response, no nzb listings found <br>This is typically a temporary nzb site issue, if it persists please let me know',
		};
	}
	return ($sh, $free, $new_nzbs, $max_nzbs, $message);
}


# Nzbsorg TV RSS extra attributes
# <newznab:attr name="seriesid" value="10460" />
# <newznab:attr name="showtitle" value="Big Brother (AU)" />
# <newznab:attr name="pred" value="Mon, 03 Sep 2012 12:47:35 +0000" />

# RSS extra attributes
# tv and movies <newznab:attr name="rating" value="6.2" />
# movies <newznab:attr name="director" value="Ryûhei Kitamura" />

# only api always has
# <newznab:attr name="guid" value="48b16230e155a7a959a57ecd65e72aa2" />

sub SiteSearchForm {
	my ($site, $site_cat, $cat_name, $keyword) = @_;
		
	print HTM qq~
	<form action="$VAR{'WfCgi'}" method="$VAR{'FormMethod'}"><P>
	<INPUT TYPE="hidden" NAME="do" VALUE="$site\_search">
	<INPUT TYPE="hidden" NAME="cn" VALUE="$cat_name">
	<INPUT TYPE="text" SIZE="20" NAME="kw" VALUE="$keyword"> 
	<SELECT NAME="sc">
	<option  value="1000">Console</option>
	<option  value="1010">&nbsp;&nbsp;Console-NDS</option>
	<option  value="1080">&nbsp;&nbsp;Console-PS3</option>
	<option  value="1030">&nbsp;&nbsp;Console-Wii</option>
	<option  value="1050">&nbsp;&nbsp;Console-Xbox 360</option>\n~;
	if ($site ne 'Dognzb'){ print HTM qq~
	<option  value="1020">&nbsp;&nbsp;Console-PSP</option>
	<option  value="1060">&nbsp;&nbsp;Console-WiiWare/VC</option>
	<option  value="1040">&nbsp;&nbsp;Console-Xbox</option>
	<option  value="1070">&nbsp;&nbsp;Console-Xbox 360 DLC</option>\n~;
	}

	print HTM qq~
	<option  value="2000">Movies</option>
	<option  value="2060">&nbsp;&nbsp;Movies-3D</option>
	<option  value="2050">&nbsp;&nbsp;Movies-BluRay</option>
	<option  value="2010">&nbsp;&nbsp;Movies-Foreign</option>
	<option  value="2040">&nbsp;&nbsp;Movies-HD</option>
	<option  value="2030">&nbsp;&nbsp;Movies-SD</option>
	<option  value="2020">&nbsp;&nbsp;Movies-other</option>

	<option  value="3000">Audio</option>
	<option  value="3030">&nbsp;&nbsp;Audio-Audiobook</option>
	<option  value="3040">&nbsp;&nbsp;Audio-Lossless</option>
	<option  value="3010">&nbsp;&nbsp;Audio-MP3</option>
	<option  value="3020">&nbsp;&nbsp;Audio-Video</option>

	<option  value="4000">PC</option>
	<option  value="4010">&nbsp;&nbsp;PC-0day</option>
	<option  value="4050">&nbsp;&nbsp;PC-Games</option>
	<option  value="4020">&nbsp;&nbsp;PC-ISO</option>
	<option  value="4030">&nbsp;&nbsp;PC-Mac</option>
	<option  value="4070">&nbsp;&nbsp;Mobile-Android</option>
	<option  value="4040">&nbsp;&nbsp;Mobile-Other</option>
	<option  value="4060">&nbsp;&nbsp;Mobile-iOS</option>

	<option  value="5000">TV</option>
	<option  value="5070">&nbsp;&nbsp;TV-Anime</option>
	<option  value="5080">&nbsp;&nbsp;TV-Documentary</option>'; 
	<option  value="5020">&nbsp;&nbsp;TV-Foreign</option>
	<option  value="5040">&nbsp;&nbsp;TV-HD</option>
	<option  value="5050">&nbsp;&nbsp;TV-Other</option>
	<option  value="5030">&nbsp;&nbsp;TV-SD</option>
	<option  value="5060">&nbsp;&nbsp;TV-Sport</option>

	<option  value="6000">XXX</option>
	<option  value="6010">&nbsp;&nbsp;XXX-DVD</option>
	<option  value="6060">&nbsp;&nbsp;XXX-ImgSet</option>
	<option  value="6050">&nbsp;&nbsp;XXX-Pack</option>
	<option  value="6020">&nbsp;&nbsp;XXX-WMV</option>
	<option  value="6030">&nbsp;&nbsp;XXX-XviD</option>
	<option  value="6040">&nbsp;&nbsp;XXX-x264</option>

	<option  value="7000">Other</option>
	<option  value="7030">&nbsp;&nbsp;Other-Comics</option>
	<option  value="7020">&nbsp;&nbsp;Other-Ebook</option>
	<option  value="7010">&nbsp;&nbsp;Other-Misc</option>\n~;
	if ($site eq 'Dognzb'){ 
		print HTM '	<option value="9000">My-Cart</option>'."\n";
	}
	else { print HTM qq~
	<option value="-2">My-Cart</option>
	<option value="-3">My-Shows</option>
	<option value="-4">My-Movies</option>\n~;
	}
	if ($site_cat and $cat_name){
		print HTM '	<option value="'.$site_cat.'" selected="selected">'.$cat_name.'</option>'."\n";
	}
	print HTM qq~
	</select>
	<INPUT TYPE="submit" VALUE="Search/Update">
	<br><small>Note: An empty search will return a (updated) browse page for the selected/current category</small></P>
	</form>\n\n~;
}

sub NzbsorgSearchForm {
	my ($site, $site_cat, $cat_name, $keyword) = @_;
		
	print HTM qq~
		<form action="$VAR{'WfCgi'}" method="$VAR{'FormMethod'}"><P>
		<INPUT TYPE="hidden" NAME="do" VALUE="$site\_search">
		<INPUT TYPE="hidden" NAME="cn" VALUE="$cat_name">
		<INPUT TYPE="text" SIZE="20" NAME="kw" VALUE="$keyword"> 
		<SELECT NAME="sc">
		<option value="0">All Categories</option>

		<option value="1000">Console</option>
		<option  value="1010">&nbsp;&nbsp;Console-NDS</option>
		<option  value="1090">&nbsp;&nbsp;Console-PS2</option>
		<option  value="1080">&nbsp;&nbsp;Console-PS3</option>
		<option  value="1020">&nbsp;&nbsp;Console-PSP</option>
		<option  value="1030">&nbsp;&nbsp;Console-Wii</option>
		<option  value="1040">&nbsp;&nbsp;Console-Xbox</option>
		<option  value="1050">&nbsp;&nbsp;Console-Xbox 360</option>
		
		<option value="2000">Movies</option>
		<option  value="2070">&nbsp;&nbsp;Movies-3D</option>
		<option  value="2010">&nbsp;&nbsp;Movies-DVD</option>
		<option  value="2060">&nbsp;&nbsp;Movies-Foreign</option>
		<option  value="2050">&nbsp;&nbsp;Movies-Other</option>
		<option  value="2020">&nbsp;&nbsp;Movies-WMV-HD</option>
		<option  value="2030">&nbsp;&nbsp;Movies-XviD</option>
		<option  value="2040">&nbsp;&nbsp;Movies-x264</option>
		
		<option value="3000">Music</option>
		<option  value="3040">&nbsp;&nbsp;Music-FLAC</option>
		<option  value="3010">&nbsp;&nbsp;Music-MP3</option>
		<option  value="3020">&nbsp;&nbsp;Music-Video</option>
		
		<option value="4000">Apps</option>
		<option  value="4010">&nbsp;&nbsp;Apps-0day</option>
		<option  value="4050">&nbsp;&nbsp;Apps-Ebook</option>
		<option  value="4020">&nbsp;&nbsp;Apps-ISO</option>
		<option  value="4030">&nbsp;&nbsp;Apps-Mac</option>
		<option  value="4040">&nbsp;&nbsp;Apps-Phone</option>
		<option  value="4060">&nbsp;&nbsp;Apps-IOS</option>
		<option  value="4070">&nbsp;&nbsp;Apps-Android</option>
		
		<option value="5000">TV</option>
		<option  value="5090">&nbsp;&nbsp;TV-BoxHD</option>
		<option  value="5070">&nbsp;&nbsp;TV-BoxSD</option>
		<option  value="5010">&nbsp;&nbsp;TV-DVD</option>
		<option  value="5080">&nbsp;&nbsp;TV-Foreign</option>
		<option  value="5040">&nbsp;&nbsp;TV-HD</option>
		<option  value="5060">&nbsp;&nbsp;TV-Other</option>
		<option  value="5030">&nbsp;&nbsp;TV-SD</option>
		
		<option value="6000">XXX</option>
		<option  value="6020">&nbsp;&nbsp;XXX-Clip</option>
		<option  value="6010">&nbsp;&nbsp;XXX-DVD</option>
		<option  value="6060">&nbsp;&nbsp;XXX-IMGSET</option>
		<option  value="6050">&nbsp;&nbsp;XXX-Pack</option>
		<option  value="6030">&nbsp;&nbsp;XXX-XviD</option>
		<option  value="6040">&nbsp;&nbsp;XXX-x264</option>
		
		<option value="7000">Other</option>
		<option  value="7010">&nbsp;&nbsp;Other-Misc</option>

		<option value="-2">My-Cart</option>
		<option value="-3">My-Shows</option>
		<option value="-4">My-Movies</option>
	~;
	if ($site_cat and $cat_name){
		print HTM qq~
		<option value="$site_cat" selected="selected">$cat_name</option>
		~;
	}
	print HTM qq~
		</select>
		<INPUT TYPE="submit" VALUE="Search/Update">
		<br><small>Note: An empty search will return a (updated) browse page for the selected/current category</small></P>
		</form>\n~;
}

# 			$sh->{$an} = {
# 				nzb_id		=> $sh->{$an}{'nzb_id'},
# 				url		=> $url,
# 				orig_title	=> $orig_title,
# 				title		=> $new_title,
# 				title_enc	=> $new_title_enc,
# 				label		=> $label,
# 				sub_label	=> $sub_label,
# 				links		=> $more_url.$imdb_link,
# 				details		=> $details,
# 				a_name		=> $an,
# 				tail		=> $tail,
# 				size		=> $size,
# 				got		=> 0,
# 			}

# was in elsif (m!^\t<title>([^<]+)</title>!){
# 			$sh->{$an}{'title'} = lc $1;
# 			#$sh->{$an}{'title'} =~ s!(\w)\.(\w)\.!$1$2!; # M.D. J.D. P.S...
# 			$sh->{$an}{'title'} =~ s![._]! !g;
# 			$sh->{$an}{'title'} =~ s! *&(amp;)? *! And !g;
# 			$sh->{$an}{'title'} =~ s!&#?\w+;!!g; # &nbsp; &#123; etc.
# 			$sh->{$an}{'title'} =~ s!\b[=&.+*#-]\b! !g; # replace w/ space
# 			#$sh->{$an}{'title'} =~ s! *[/,;-] *!-!g; # chained names
# 			$sh->{$an}{'title'} =~ s![:;()"',@\!./?*#\\]!!g; # del all not handled above
# 			# yr
# 			if ($sh->{$an}{'title'} =~ s!(.+?) (19[3-9]\d|20[01]\d)(.*)!$1!){
# 				$sh->{$an}{'year'} = $2;
# 				$sh->{$an}{'tail'} = $3;
# 			}
# 			# SE
# 			elsif ($sh->{$an}{'title'} =~ s!(.+?) S\d+(E\d+)?(.+)!$1!i){
# 				$sh->{$an}{'tail'} = $3;
# 			}
# 			# SxE
# 			elsif ($sh->{$an}{'title'} =~ s!(.+?) \d{1,3}x\d{2,4}(.+)!$1!i){
# 				$sh->{$an}{'tail'} = $2;
# 			}
# 			# \d\d-\d\d-\d\d
# 			elsif ($sh->{$an}{'title'} =~ s!(.+?) \d{2,4}[ -]\d{2}[ -]\d{2}(.+)!$1!i){
# 				$sh->{$an}{'tail'} = $2;
# 			}
# # 			# part
# # 			elsif ($sh->{$an}{'title'} =~ s!(.+?) Part *(one|two|three|four|five|six|seven|eight|nine|ten|\d+|IX|IV|III|II|I|VIII|VII|VI|V|X)(.*)!$1!i){
# # 				my $num = lc $2;
# # 				$sh->{$an}{'tail'} = $3;
# # 				my %ep = ( one => 1, two => 2, three => 3, four => 4, five => 5, six => 6, seven => 7, eight => 8, nine => 9, ten => 10,
# # 				i => 1, ii => 2, iii => 3, iv => 4, v => 5, vi => 6, vii => 7, viii => 8, ix => 9, x => 10, );
# # 				if ($ep{$num}){ $sh->{$an}{'EpLabel'} = 'pt'.$ep{$num}; }
# # 				else { $sh->{$an}{'EpLabel'} = 'pt'.$num; }
# # 				# Part # for movies
# # 				# also need #, III etc. parsing/handling
# # 				# III => 3,
# # 				# 3 => III,
# # 				# VII => 7,
# # 				# 7 => VII,
# # 			}
# 			elsif ($sh->{$an}{'title'} =~ s!(.+?)[ -]+(dvd ?rip|Avchd|Pittis|Uncut|Staffel|Blu ?Ray).*!$1!i){
# 			}
# 			
# 			# \d of \d label
# 			$sh->{$an}{'of'} = '';
# 			if ($sh->{$an}{'tail'} and $sh->{$an}{'tail'} =~ m!(\d+) ?of ?(\d+)!i){
# 				$sh->{$an}{'of'} = ' - '.$1.'/'.$2;
# 			}
# 			
# 			# elsif e\d s\d \d III iii
# 			$sh->{$an}{'title'} =~ s! (i+)! \u$1!g; # ii, iii... > II, III...
# 			$sh->{$an}{'title'} =~ s! (\w)! \u$1!g; # convert first word letter to upper case
# 			$sh->{$an}{'title'} =~ s!^(\w)!\u$1!; # beginning of name to uc

# description - RSS
# 	ID
# 	Name
# 	Size
# 	Attributes
# 	Groups
# 	Poster
# 	PostDate
# 	Password

# title - DN
# guid - DN
# link - DN
# comments - DN
# pubDate - DN
# category - DN
# description - API = just title - DN
# enclosure - DN

# category - DN
# category - DN
# size - DN
# guid - DN
# files
# poster

# season
# episode
# rageid
# tvtitle
# tvairdate

# imdb
# imdbtitle
# imdbtagline
# imdbplot
# imdbscore
# genre
# imdbyear
# imdbdirector
# imdbactors
# coverurl

# grabs
# comments
# password
# usenetdate
# group

# 1000 => 'Filme',
# 1010 => 'Filme-Cine',
# 1020 => 'Filme-XviD',
# 1030 => 'Filme-DVD',
# 1040 => 'Filme-3D',
# 1050 => 'Filme-720p',
# 1060 => 'Filme-1080p',
# 1070 => 'Filme-Complete-BD',
# 1080 => 'Filme-Remux',
# 1100 => 'Filme-X264',
# 1090 => 'Filme-Sonstige',
# 
# 9000 => 'Movies-All',
# 9090 => 'Cine',
# 9100 => 'XviD',
# 9120 => 'DVD',
# 9130 => '3D',
# 9140 => '720p',
# 9150 => '1080p',
# 9160 => 'Complete-BD',
# 9110 => 'X264',
# 9170 => 'Other',
# 
# 2000 => 'TV-Serien',
# 2010 => 'Serien-XviD',
# 2020 => 'Serien-DVD',
# 2030 => 'Serien-720p',
# 2040 => 'Serien-1080p',
# 2110 => 'Serien-X264',
# 2041 => 'Serien-Subbed',
# 2050 => 'Doku-XviD',
# 2060 => 'Doku-720p',
# 2070 => 'Doku-1080p',
# 2120 => 'Doku-X264',
# 2080 => 'Serien-Sport',
# 2090 => 'Serien-Anime',
# 2100 => 'Serien-Sonstige',
# 
# 8000 => 'TV-All',
# 8110 => 'XviD',
# 8120 => 'DVD',
# 8130 => '720p',
# 8140 => '1080p',
# 8150 => 'X264',
# 8160 => 'Docu-XviD',
# 8170 => 'Docu-720p',
# 8180 => 'Docu-1080p',
# 8190 => 'Docu-X264',
# 8200 => 'Sport',
# 8210 => 'Others',
# 
# 3000 => 'Games-All',
# 3020 => 'PC',
# 3100 => 'PC-Updates',
# 3030 => 'PS3',
# 3040 => 'PSP',
# 3050 => 'Wii',
# 3060 => 'Wii-Ware',
# 3070 => 'XBOX',
# 3080 => 'XBOX360',
# 3090 => 'XBOX360DLC',
# 
# 4000 => 'Audio-All',
# 4010 => 'MP3',
# 4020 => 'Charts',
# 4030 => 'DVD',
# 4040 => 'Video',
# 4050 => 'Audiobooks',
# 4060 => 'Tonspuren',
# 4070 => 'Flac',
# 
# 5000 => 'Programs-All',
# 5010 => 'PC',
# 5020 => 'Mac',
# 5030 => 'Smartphone',
# 5040 => '0Day',
# 
# 6000 => 'XXX-All',
# 6010 => 'XviD',
# 6020 => 'WMV',
# 6030 => 'DVD',
# 6040 => 'HD',
# 6050 => 'IMAGESET',
# 
# 7000 => 'Misc-All',
# 7010 => 'Unknown',
# 7020 => 'EBooks',
# 7030 => 'Comics',


1;

